#coding:utf8

import os
import re

field_pattern = re.compile(r'[\ ]{0,10}[a-z|A-Z]{1,20}[\ ]{1,20}[a-z|A-Z|0-9|\<|\>]{0,40}[\ ]{1,20}[a-z|A-Z|0-9|\_]{1,30}\;[\ ]{0,4}')
def change_file(file_path):
    if not os.path.isdir(file_path) and not os.path.isfile(file_path):
        print "file not found"
        return
    file_pointer = open(file_path)
    line = file_pointer.readline()
    while line:
        line = line.replace("\n","")
        output_file_content(line)
        line = file_pointer.readline()

    file_pointer.close()


def output_file_content(line):
    if line.find("@FieldDoc") >= 0:
        line = line.replace('(\"', '|').replace('\")','|')
        array = line.split('|')
        print "/**"
        print "* " + array[1]
        print "*/"
        return
    if line.find("@JsonProperty") >= 0:
        print line
        return

    group = field_pattern.match(line)
    if group:
        print group.string.replace('\n','')
        return

def test_output_file_content1():
    line = "public class ChOrderInfo implements SpecificRecord {"
    output_file_content(line)
    
def test_output_file_content2():
    line = '@FieldDoc("供应商ID不允许为空")'
    output_file_content(line)

def test_re_method():
    line = 'private String vendorId;'
    group = field_pattern.match(line)
    if group:
        print group.string

    line = 'private BigInter vendorId;'
    group = field_pattern.match(line)
    if group:
        print group.string


    line = 'private String driverVehicleTypeBrand;'
    group = field_pattern.match(line)
    if group:
        print group.string

    line = '@JsonProperty("VendorName")'
    group = field_pattern.match(line)
    if group:
        print group.string


if __name__ == '__main__':
    change_file('data.txt')